import fs from 'fs';

//获取给定路径下所有的js文件

export function findRouter(conpath){
    let tpath=conpath|| './Controller';
    let files=fs.readdirSync(tpath);

    return files;
}

//传入JS文件数组和路由实况，注册路由

export function reRouter(files,router){
    let tpath='../Controller'
    files.forEach(async file=>{
        let filepath=tpath+'/'+file;
        let tmpModule=await import(filepath);
        let temobj=tmpModule.default;
        for(let i in temobj){
            let temArr=i.split(' ');
            let method=temArr[0];
            let fn=temobj[i];
            let path=temArr[1];
            router[method](path,fn);
        }
    })
}